home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Random / Commodore 64c / SOURCE / Menus.c < prev    next >
Text File  |  1994-03-19  |  5KB  |  263 lines

  1. /*
  2.     Commodore 64 Emulator v0.2      Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include "Menus.h"
  20. #include "Error.h"
  21.  
  22. #define kAboutDialog 131
  23. Handle menuBar;
  24. MenuHandle appleMenu, fileMenu, editMenu, deviceMenu, testMenu;
  25.  
  26.  
  27. int MenuInitialize()
  28. {
  29.     menuBar=GetNewMBar(128);
  30.     if (menuBar==nil) return kMissingResource;
  31.     SetMenuBar(menuBar);
  32.     
  33.     appleMenu=GetMenu(kAppleMenu);
  34.     if (appleMenu==nil) return kMissingResource;
  35.     AddResMenu(appleMenu, 'DRVR');
  36.     
  37.     fileMenu=GetMenu(kFileMenu);
  38.     if (fileMenu==nil) return kMissingResource;
  39.     editMenu=GetMenu(kEditMenu);
  40.     if (editMenu==nil) return kMissingResource;
  41.     deviceMenu=GetMenu(kDeviceMenu);
  42.     if (deviceMenu==nil) return kMissingResource;
  43.     testMenu=GetMenu(kTestMenu);
  44.     if (testMenu==nil) return kMissingResource;
  45.     
  46.     DisableItem(editMenu, 1);
  47.     DrawMenuBar();
  48. }
  49.  
  50.  
  51. void DoMenuChoice(long menuChoice)
  52. {
  53.     int theMenu, theItem;
  54.     
  55.     if (menuChoice==0)
  56.     {
  57.         HiliteMenu(0);
  58.         return;
  59.     }
  60.  
  61.     theMenu=HiWord(menuChoice);
  62.     theItem=LoWord(menuChoice);
  63.  
  64.     HiliteMenu(theMenu);
  65.  
  66.     switch(theMenu)
  67.     {
  68.         case kAppleMenu:
  69.             DoAppleMenu(theItem);
  70.             break;
  71.             
  72.         case kFileMenu:
  73.             DoFileMenu(theItem);
  74.             break;
  75.             
  76.         case kEditMenu:
  77.             DoEditMenu(theItem);
  78.             break;
  79.             
  80.         case kDeviceMenu:
  81.             DoDeviceMenu(theItem);
  82.             break;
  83.             
  84.         case kTestMenu:
  85.             DoTestMenu(theItem);
  86.             break;
  87.     }
  88.  
  89.     HiliteMenu(0);
  90. }
  91.  
  92.  
  93. void DoAppleMenu(int theItem)
  94. {
  95.     EventRecord event;
  96.     Str255 daName;
  97.     DialogPtr dialog;
  98.     int done;
  99.     
  100.     switch (theItem)
  101.     {
  102.         case kAbout:
  103.             /* Draw About window */
  104.             dialog=GetNewDialog(kAboutDialog, nil, (WindowPtr)-1L);
  105.             ShowWindow(dialog);
  106.             DrawDialog(dialog);
  107.             
  108.             /* Handle events until time to drop window */
  109.             done=0;
  110.             while (!done) {
  111.                 FlushEvents(0,-1);
  112.                 WaitNextEvent(everyEvent, &event, 60L, nil);
  113.                 switch(event.what)
  114.                 {
  115.                     /* On keypress or buttonpress stop waiting */
  116.                     case mouseDown:    done=1; break;
  117.                     case autoKey:    done=1; break;
  118.                     case keyDown:    done=1; break;
  119.                     
  120.                     /* *Must* tell event manager we're "updating" */
  121.                     case updateEvt:
  122.                         BeginUpdate((WindowPtr)event.message);
  123.                         EndUpdate((WindowPtr)event.message); break;
  124.                 }
  125.             }
  126.             
  127.             /* Drop window and redraw the VIC screen */
  128.             HideWindow(dialog);
  129.             DisposDialog(dialog);
  130.             TotalRedrawVIC();
  131.             break;
  132.             
  133.         default:
  134.             /* Run the selected Desk Accessory */
  135.             GetItem(appleMenu, theItem, daName);
  136.             OpenDeskAcc(daName);
  137.             break;
  138.         }
  139. }
  140.  
  141.  
  142. void DoFileMenu(int theItem)
  143. {
  144.     switch(theItem)
  145.     {
  146.         case kOpenRAM:
  147.             LoadRAM();
  148.             break;
  149.             
  150.         case kSaveRAM:
  151.             SaveRAM();
  152.             break;
  153.             
  154.         case kReset:
  155.             /* Clear the menu hilite, since we're gonna be away a while */
  156.             HiliteMenu(0);
  157.             /* Reset PC, memory map */
  158.             RegisterInitialize();
  159.             /* Go compute */
  160.             ProcessorLoop();
  161.             break;
  162.             
  163.         case kPageSetup:
  164.             break;
  165.             
  166.         case kPrint:
  167.             break;
  168.  
  169.         case kPrefs:
  170.             break;
  171.  
  172.         case kQuit:
  173.             CleanUpCommodore();
  174.             ExitToShell();
  175.             break;
  176.     }
  177. }
  178.  
  179.  
  180. void DoEditMenu(int theItem)
  181. {
  182.     switch(theItem)
  183.     {
  184.         case kUndo:
  185.             break;
  186.             
  187.         case kCut:
  188.             break;
  189.             
  190.         case kCopy:
  191.             break;
  192.             
  193.         case kPaste:
  194.             break;
  195.             
  196.         case kClear:
  197.             break;
  198.     }
  199. }
  200.  
  201.  
  202. void DoDeviceMenu(int theItem)
  203. {
  204.     switch(theItem)
  205.     {
  206.         case kCreateImage:
  207.             FloppyCreateImage();
  208.             break;
  209.             
  210.         case kSelectImage:
  211.             FloppySelectImage();
  212.             break;
  213.             
  214.         case kDirectory:
  215.             FloppyDirectory();
  216.             break;
  217.             
  218.         case kCopyTo:
  219.             FloppyCopyTo();
  220.             break;
  221.             
  222.         case kCopyFrom:
  223.             FloppyCopyFrom();
  224.             break;
  225.             
  226.         case kChdir:
  227.             HardChangeDirectory();
  228.             break;
  229.             
  230.         case kNewPFile:
  231.             PrinterNewFile();
  232.             break;
  233.         
  234.         case kAppendPFile:
  235.             PrinterAppendFile();
  236.             break;
  237.         
  238.         case kXvert:
  239.             PrinterXvertCharacters();
  240.             break;
  241.         
  242.         case kDisplayPFile:
  243.             PrinterDisplayFile();
  244.             break;
  245.         
  246.         case kLoadTape:
  247.             LoadTape();
  248.             break;
  249.     }
  250. }
  251.  
  252. void DoTestMenu(int theItem)
  253. {
  254.     switch(theItem)
  255.     {
  256.         case kTest68k:
  257.             Test68k();
  258.             break;
  259.         
  260.         case kTestVIC:
  261.             break;
  262.     }
  263. }